package Tests.FunctionalTests;

import harima.collision.bodies.BodiesContext;
import harima.collision.bodies.Body;
import harima.collision.bodies.Direction;
import harima.collision.bodies.JumpUpdater;
import harima.collision.bodies.PathNode;
import harima.collision.bodies.PlatformBody;
import harima.collision.bodies.PlatformPath;
import harima.collision.bodies.PlatformUpdater;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.util.ArrayList;





import com.golden.gamedev.Game;
import com.golden.gamedev.GameLoader;

public class  Collision extends Game {

	BodiesContext context;
	Body floor;
	Body box;
	PlatformBody platform;
	PlatformUpdater platformUpdater;
	JumpUpdater jumper;
	float speed = 1.3f;
	ArrayList<String> lista;
	
	
	@Override
	public void initResources() {
		// TODO Auto-generated method stub
		context = new BodiesContext();
		floor = new Body(400, 10);
		floor.y = 250;
		box= new Body(30,30);
		box.setSolid(true);
		Body blok = new PlatformBody(10,40);
		blok.x = 200;
		blok.y = 170;
		platform = new PlatformBody(60f,5f, .3f);
		platform.x  = 0;
		platform.y  = 230;
		
		context.add(floor);
		context.add(box);
		context.add(platform);
		context.add(blok);
		
		jumper = new JumpUpdater(box, 2.8f, (short)3);
		jumper.setGravity(.1f);
		PlatformPath path = new PlatformPath();
		path.addNode(new PathNode(Direction.Right, 200));
		path.addNode(new PathNode(Direction.Up, 200));
		
		
		platformUpdater = new PlatformUpdater(platform, path);
	}

	@Override
	public void render(Graphics2D g) {
		// TODO Auto-generated method stub
		g.setColor(Color.black);
		g.fillRect(0, 0, 400, 300);
		g.setColor(Color.white);
		for(Body item : context.getBodies())
		{
			g.draw(item);
		}
	}

	@Override
	public void update(long arg0) {
		// TODO Auto-generated method stub
		if(bsInput.isKeyDown(KeyEvent.VK_DOWN) && box.canMove(Direction.Down, speed))
		{
			box.move(Direction.Down, speed);
		}
		if(bsInput.isKeyPressed(KeyEvent.VK_UP) && box.canMove(Direction.Up, speed))
		{
			jumper.jump();
		}
		if(bsInput.isKeyDown(KeyEvent.VK_LEFT) && box.canMove(Direction.Left, speed))
		{
			box.move(Direction.Left, speed);
		}
		if(bsInput.isKeyDown(KeyEvent.VK_RIGHT) && box.canMove(Direction.Right, speed))
		{
			box.move(Direction.Right, speed);
		}
		
		jumper.updateBody(arg0);
		platformUpdater.updateBody(arg0);
	}
	
	public static void main(String[] a)
	{
		GameLoader loader = new GameLoader();
		loader.setup(new Collision(), new Dimension(400,300), false);
		loader.start();
	}

}
